import time
from threading import Thread


# 需求：采用两个线程累加1,5亿次
def add(n):
    """
    把1累加多少次
    :param n:
    :return:
    """
    sum = 0
    while sum < 0:
        sum += 1
    print(f'当前线程加了{n}次')


if __name__ == '__main__':
    start = time.time()
    n = 500000000

    # daemon=True 设置为守护线程
    t1 = Thread(target=add, args=(n / 2,), daemon=True)
    t2 = Thread(target=add, args=(n / 2,), daemon=True)

    t1.start()
    t2.start()

    # t1.join()
    # t2.join()

    end = time.time()
    print(f'运行的时间为{end - start}')
